<template>
  <div class="icons">
    <swiper :options="swiperOption">
       <swiper-slide v-for="(page, index) of pages" :key="index">
         <div class="icons-box" v-for='item of page' :key="item.id">
          <div class="icons-img">
            <img class="img-one" :src="item.imgUrl"/>
          </div>
          <div class="icons-text">{{item.desc}}</div>
         </div>
       </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'Icon',
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  props: {
    iconlist: Array
  },
  computed: {
    pages () {
      const pages = []
      this.iconlist.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
 .icons
  overflow: hidden
  height:0
  padding-bottom: 50%
  margin-top: .2rem
  .icons-box
    float: left
    position: relative
    overflow: hidden
    height:0
    width: 25%
    padding-bottom: 25%
    .icons-img
      position: absolute
      top: 0
      left: 0
      right: 0
      bottom: .44rem
      .img-one
       display: block
       width: 75%
       height: 75%
       margin: 0 auto
       border-radius: .2rem
    .icons-text
     position: absolute
     bottom: .2rem
     left: 0
     right: 0
     height: .44rem
     line-height: .44rem
     text-align: center
</style>
